#from demo.Minist_cnn import *
import numpy as np
import keras
from flask import Flask, escape, request
import matplotlib.image as mp
import tensorflow as tf

class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
               'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']

app = Flask(__name__)
graph = tf.get_default_graph()
new_model = keras.models.load_model('minist.h5')


@app.route('/test1', methods=['GET', 'POST'])
def findClassLabel():
    global graph
    file = request.files.get('file')
    img = mp.imread(file)
    print(img)
    img = (np.expand_dims(img, 2))
    img = (np.expand_dims(img, 0))
    with graph.as_default():
        predictions_single = new_model.predict(img)
    label = np.argmax(predictions_single[0])
    print(class_names[label])
    return str(class_names[label])


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)


